package com.hay.goods.listener;

import com.hay.goods.service.GoodsHtmlService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @title: GoodsListener
 * @Author HuangYan
 * @Date: 2020/7/31 17:37
 * @Version 1.0
 */
@Component
public class GoodsListener {

    @Autowired
    private GoodsHtmlService goodsHtmlService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "LEYOU.WEB.SAVE.QUEUE", ignoreDeclarationExceptions = "true", durable = "true"),
            exchange = @Exchange(value = "LEYOU.ITEM.EXCHANGE", type = ExchangeTypes.TOPIC, ignoreDeclarationExceptions = "true"),
            key = {"leyou.item.insert", "leyou.item.update"}
    ))
    public void save(Long id){
        if (id == null){
            return;
        }
        goodsHtmlService.pageToStatic(id);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "LEYOU.WEB.DELETE.QUEUE", ignoreDeclarationExceptions = "true", durable = "true"),
            exchange = @Exchange(value = "LEYOU.ITEM.EXCHANGE", type = ExchangeTypes.TOPIC, ignoreDeclarationExceptions = "true"),
            key = {"leyou.item.delete"}
    ))
    public void delete(Long id){
        if (id == null){
            return;
        }
        goodsHtmlService.delete(id);
    }
}
